<?php
namespace Home\Model;
use Think\Model;
class ConnectModel extends Model{

    //定义表单能接收哪些字段
    protected $insertFields = 'dpasum,requester,givename,givetime,givelocation,getname,gettime,getlocation,tel';
    protected $updateFields = 'id,dpasum,requester,givename,givetime,givelocation,getname,gettime,getlocation,tel';
    //字段验证
    protected $_validate = array(
        array('dpasum','require','报告号不能为空',1),
        array('dpasum','','报告号不能重复',1,'unique',1),
        array('requester','require','委托单位不能重复',1),
        array('givename','require','发放人不能为空',1),
        array('givetime','require','发放时间不能为空',1),
        array('givelocation','require','发放地点不能为空',1),
        array('getname','require','接收人不能为空',1),
        array('gettime','require','接收时间不能为空',1),
        array('getlocation','require','接收地点不能为空',1),
        array('tel','require','接收人手机不能为空',1),
    );

    public function seach(){
        $dpasum = I('get.dpasum');
        $givename = I('get.givename');
        $getname = I('get.getname');
        if($dpasum){
            $where['dpasum'] = array('like',"%".$dpasum."%");
        }
        if($givename){
            $where['givename'] = array('like',"%".$givename."%");
        }
        if($getname){
            $where['getname'] = array('like',"%".$getname."%");
        }
        $coun = $this->where($where)->count();
        $page = new \Think\Page($coun,20);
        $page->setConfig('prev','上一页');
        $page->setConfig('next','下一页');
        $list = $this->where($where)->limit($page->firstRow,$page->listRows)->select();
        return array(
            'list' => $list,
            'page_str' => $page->show()
        );
    }
}